package com.jameci.luntan.controller;

import com.jameci.luntan.dto.PaginationDTO;
import com.jameci.luntan.service.PostService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class IndexController {
    @Autowired
    private PostService postService;
    @GetMapping(value = {"/", "/index"})
    public String index(
            HttpServletRequest request,
            Model model,
            @RequestParam(name = "page", defaultValue = "1") int page,
            @RequestParam(name = "size", defaultValue = "5") int size
    ) {
        PaginationDTO paginationDTO = postService.list(page, size);
        model.addAttribute("paginationDTO", paginationDTO);
        return "index";
    }
}
